Rainier.UI.V2.TextOvalFigure = draw2d.shape.basic.Oval.extend({
  NAME: "Rainier.UI.V2.TextOvalFigure",

  /**
   * @名称
   * @功能   初始化器件的参数值
   * @author 李姣
   * @data   2019-05-22
   * @param  {[type]}   modelProperties [description]
   * @return {[type]}                   [description]
   */
  init: function (modelProperties, setter, getter) {
    var _this = this;
    this.properties = modelProperties;
    this.uiProperty = modelProperties.uiProperty;
    var attrs = {
      stroke: modelProperties.uiProperty.stroke,
      color: modelProperties.uiProperty.color,
      width: modelProperties.uiProperty.width,
      height: modelProperties.uiProperty.height,
      // "svgString" : modelProperties.uiProperty.imageString,
      bgColor: modelProperties.uiProperty.bgColor,
      radius: modelProperties.uiProperty.radius,
    };
    this.symbolLabelFigure = null; //符号图元

    this._super(attrs);
    var text = modelProperties.modelProperty.text;
    var dotNum = this.getDotNum(text);
    // if(dotNum <= 8){
    this.label = new draw2d.shape.basic.Text({
      text: text,
      bold: this.uiProperty.bold,
      fontColor: this.uiProperty.color,
      fontSize: this.uiProperty.fontSize,
      fontFamily: this.uiProperty.fontFamily,
      stroke: 0,
      width: this.uiProperty.width - 9,
      height: this.uiProperty.height / 2,
    });
    // }else{
    // this.label = new draw2d.shape.basic.Text({text:text, bold:this.uiProperty.bold, fontColor:this.uiProperty.color,fontSize:this.uiProperty.fontSize,fontFamily:this.uiProperty.fontFamily, stroke:0,width:this.uiProperty.width-9,height:this.uiProperty.height/2});
    // }

    this.label.on("change:width", $.proxy(this.widthChanged, this));
    this.label.setWidth(this.uiProperty.width - 54);

    // add the new decoration to the connection with a position locator.
    //
    this.add(this.label, new draw2d.layout.locator.CenterLocator(this));

    this.label.on("change:text", $.proxy(this.valueChanged, this));
    // this.label.installEditor(new draw2d.ui.LabelInplaceEditor());

    var policyAttrs = { recBgColor: "#0BF60E", lineColor: "#2C70FF" };
    this.installEditPolicy(new Rainier.UI.V2.RectangleSelectionFeedbackPolicy(policyAttrs));
    this.on("resize", $.proxy(this.textFigureResize, this));
  },

  /**
   * @名称   setSvgString
   * @功能   设置模型的 svg 图片
   * @author 杨顺强
   * @data   2017-09-21
   * @param  {[type]}   svgString [description]
   */
  setSvgString: function (svgString) {
    this.svgString = svgString;
    var attrs = {
      src: svgString,
    };
    // this.repaint(attrs);
    var canvas = this.canvas;

    //此处重在重新计算 图元需要显示的图形
    this.setCanvas(null);
    this.setCanvas(canvas);
    this.setPosition(this.x, this.y);
  },

  /**
   * @名称   repaint
   * @功能   绘制图元
   * @author 杨顺强
   * @data   2017-09-21
   * @param  {[type]}   attributes [description]
   * @return {[type]}              [description]
   */
  repaint: function (attributes) {
    this._super(attributes);
  },

  /**
   * @名称   createSet
   * @功能   创建需要绘制的图形集合
   * @author 杨顺强
   * @data   2017-09-21
   * @return {[type]}   [description]
   */
  createSet: function () {
    var bgImage = this._super();
    var set = this.canvas.paper.set();
    if (bgImage) {
      set.push(bgImage);
    }
    set.attr({ stroke: 2 });

    return set;
  },

  /**
   * @名称   valueChanged
   * @功能   label值发生变化时，向外发出事件
   * @author 杨顺强
   * @data   2018-01-31
   * @param  {[type]}   changedObj [description]
   * @return {[type]}              [description]
   */
  valueChanged: function (eventSource, paramObj) {
    this.fireEvent("change:text", paramObj);
  },

  /**
   * @名称   fontSizeChanged
   * @功能   label字号发生变化时，向外发出事件
   * @author 李姣
   * @data   2019-05-09
   * @param  {[type]}   changedObj [description]
   * @return {[type]}              [description]
   */
  fontSizeChanged: function (eventSource, paramObj) {
    this.fireEvent("change:fontSize", paramObj);
  },

  /**
   * @名称   dimensionChanged
   * @功能   label宽度高度发生变化时，向外发出事件
   * @author 李姣
   * @data   2019-05-14
   * @param  {[type]}   changedObj [description]
   * @return {[type]}              [description]
   */
  dimensionChanged: function (eventSource, paramObj) {
    this.fireEvent("change:dimension", paramObj);
  },

  /**
   * @名称   widthChanged
   * @功能   label宽度发生变化时，向外发出事件
   * @author 李姣
   * @data   2019-05-13
   * @param  {[type]}   changedObj [description]
   * @return {[type]}              [description]
   */
  widthChanged: function (eventSource, paramObj) {
    // console.log(paramObj);
    this.fireEvent("change:width", paramObj);
  },

  /**
   * @名称   heightChanged
   * @功能   label高度发生变化时，向外发出事件
   * @author 李姣
   * @data   2019-05-13
   * @param  {[type]}   changedObj [description]
   * @return {[type]}              [description]
   */
  heightChanged: function (eventSource, paramObj) {
    this.fireEvent("change:height", paramObj);
  },

  /**
   * @名称   textFigureResize
   * @功能   text label值发生变化时，向外发出事件
   * @author 李姣
   * @data   2018-08-31
   * @param  {[type]}   changedObj [description]
   * @return {[type]}              [description]
   */
  textFigureResize: function (eventSource, paramObj) {
    this.fireEvent("resize");
    // this.fireEvent("change:dimension",{value:{width:this.width, height:this.height}});
  },

  /**
   * 函数名称：Rainier.UI.V2.TextFigure.setSymbolLabelFigure<br>
   * 函数功能：设置Label<br>
   * 参数输入：<br>
   * property:属性对象<br>
   * sLocator:定位器构造函数<br>
   * x:Number<br>
   * y:Number<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  setSymbolLabelFigure: function (property, sLocator, x, y) {
    var locator = null;
    if (!sLocator || sLocator === "default") {
      locator = new Rainier.UI.V2.XYAbsFigureLocator(x, y);
    } else {
      locator = eval("new " + sLocator + "();");
      locator.offsetX = x;
      locator.offsetY = y;
    }
    property.stroke = 0;
    this.symbolLabelFigure = new Rainier.UI.V2.DeviceSymbolLabelFigure(property, locator);
    this.add(this.symbolLabelFigure, locator);
  },

  /**
   * 函数名称：Rainier.UI.V2.TextFigure.showLabel<br>
   * 函数功能：显示标签<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  showLabel: function () {
    this.labelVisible = false;
    if (this.symbolLabelFigure) {
      this.symbolLabelFigure.setVisible(true);
    }
  },

  /**
   * 函数名称：Rainier.UI.V2.DeviceBoxFigure.unshowLabel<br>
   * 函数功能：隐藏标签<br>
   * 函数返回：无<br>
   * 异常信息：无<br>
   */
  unshowLabel: function () {
    this.labelVisible = false;
    if (this.symbolLabelFigure) {
      this.symbolLabelFigure.setVisible(false);
    }
  },

  /**
   * 函数名称：Rainier.UI.V2.TextFigure.getLabel<br>
   * 函数功能：获取label标签<br>
   * 函数返回：label标签属性<br>
   * 异常信息：无<br>
   */
  getLabel: function () {
    return this.label;
  },

  /**
   * 函数名称：Rainier.UI.V2.TextFigure.getLabel<br>
   * 函数功能：获取label标签中.出现的次数<br>
   * 函数返回：.出现的次数<br>
   * 异常信息：无<br>
   */
  getDotNum: function (text) {
    var count = 0;
    var pos = text.indexOf(".");
    while (pos !== -1) {
      count++;
      pos = text.indexOf(".", pos + 1);
    }
    return count;
  },
});
